import java.lang.reflect.Field;

/**
 * Created by BlueDream on 2018-04-11.
 */
public class Test {

    public static void main(String[] args) {
        Integer a = 1;
        Integer b = 4;
        swap(a, b);
        System.out.println("a=" + a + ";b=" + b);
    }

    private static void swap(Integer a, Integer b) {
        int tmp =a;
        try {
            Class<?> aClass = Class.forName(a.getClass().getName());
            Field f = aClass.getDeclaredField("value");
            f.setAccessible(true);
            f.set(a,2);
            f.set(b,tmp);
            f.setInt(b, tmp);
            f.set(b, new Integer(tmp));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
